#include "stdafx.h"

#include "../Watch/Watch.h"
#include "WatchTests.h"

static int g_nFailed=0, g_nPassed=0;

static CStreamOnWriteStream g_out_strm;
static CWriteStreamOnFile g_file_strm;
CStreamFormatter g_out;

#define TEST(x) _test(&g_out_strm, x, _T(#x), argc, argv);

static int _test(IStream *pOut, int (*f)(int,LPCSTR[]), LPCTSTR szMsg, int argc, LPCSTR argv[])
{
	int r = f(argc,argv);
	CStreamFormatter sf;
	sf.Initialize(pOut);

	if(r==0)
	{
		sf.WriteRaw(_T("PASSED "));
		g_nPassed++;
	}else
	{
		sf.WriteFormatted(_T("FAILED(%d)"),r);
		g_nFailed++;
	}
	sf.WriteRaw(szMsg);
	return r;
}


int main(int argc, LPCSTR argv[])
{
	if(FAILED(g_file_strm.Initialize(_T("DtourTest.log"), true)))
	{
		ATLTRACE( _T("WATCH: File DtourTest.log couldn't be opened.\r\n") );
		return -1;
	}

	g_out_strm.Init(&g_file_strm);
	g_out.Initialize(&g_out_strm);

	TEST(testDtour1);

	g_out.WriteFormatted(_T("\r\n\r\nPASSED: %d\t\tFAILED: %d\r\n"),g_nPassed, g_nFailed);
	g_file_strm.FlushStream();

	return g_nFailed;
}